<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form :inline="true" :model="formModel">
        <el-form-item class="no-warn-item" label="模块:" prop="tmBasModuleId">
          <el-select v-model="formModel.tmBasModuleId" clearable filterable>
            <el-option v-for="item in moduleOptions" :key="item.tmBasModuleId" :label="item.moduleCode+'-'+item.moduleDesc" :value="item.tmBasModuleId"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="no-warn-item" label="识别码:" prop="markCode">
          <el-input
            v-model="formModel.markCode"
            class="filter-item "
            clearable
          />
        </el-form-item>
        <el-row class="submit-area">
          <el-col :span="24">
            <el-button type="primary" v-if="hasPermission('module_bsc_info_select')" plain @click="queryList(false)">查询</el-button>
            <el-button type="primary" v-if="hasPermission('module_bsc_info_add')" plain @click="handleAdd">新增</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <h3>模块基础信息列表:</h3>
    <hey-table ref="table" :columns="columns" @row-click="handleRowClick" :auto-width="false" :is-radio="true">

    </hey-table>
    <div class="filter-container">
      <el-row class="submit-area">
        <el-col :span="24">
          <el-button type="primary" v-if="hasPermission('ew_audit')" plain @click="handleEw">EW审核</el-button>
          <el-button type="primary" v-if="hasPermission('mw_audit')" plain @click="handleMw">MW审核</el-button>
          <el-button type="primary" v-if="hasPermission('filed_version_add')" plain @click="handleAddVersion">新增字段版本</el-button>
        </el-col>
      </el-row>
    </div>
    <h3>详细信息列表:</h3>
    <hey-table ref="table1" :table-data="tableData1" :columns="columns1" @row-click="chooseTable" :is-radio="true"/>
    <el-dialog
      v-dialogDrag
      v-if="dialogVisible"
      :close-on-click-modal="false"
      title="模块基础信息"
      :visible.sync="dialogVisible"
      width="80%"
    >
      <module-bsc-info-mnt :page-type="operType" :edit-data="editData" @mntSuc="queryList" />
    </el-dialog>
    <el-dialog
      v-dialogDrag
      v-if="showAudit"
      :close-on-click-modal="false"
      title="模块基础信息审核"
      :visible.sync="showAudit"
      width="80%"
    >
      <module-bsc-info-audit :page-type="operType" :edit-data="editData" @mntSuc="queryList1" />
    </el-dialog>

  </div>
</template>

<script>
  export default {
    name: 'ModuleBscLnfoList',
    components: {
      ModuleBscInfoMnt: () => import('./module-bsc-info-mnt'),
      ModuleBscInfoAudit: () => import('./module-bsc-info-audit'),
    },
    props: {},
    data() {
      return {
        dialogVisible: false,
        showAudit: false,
        operType: '',
        editData: {},
        chooseData: {},
        chooseTable1: {},
        tableData1:[],
        moduleOptions:[],
        formModel: {
          tmBasModuleId: '',
          markCode: '',
          isDelete: '0',
        },
        columns: [
          { title: '模块代码', key: 'moduleCode'},
          { title: '模块描述', key: 'moduleDesc'},
          { title: '识别码', key: 'markCode'},
          { title: '创建时间', key: 'createTime' },
          { title: '创建人', key: 'createUsername' },
          { title: '最后修改时间', key: 'lastUpdateTime'},
          { title: '最后修改人', key: 'lastUpdateUsername' },
        ],
        columns1: [
          { title: '字段代码', key: 'filedCode' },
          { title: '字段描述', key: 'filedDesc' },
          { title: '字段类型', key: 'filedType',clcd:'Key_ECU_Module_Filed'},
          { title: '字段值', key: 'filedValue' },
          { title: '发布状态', key: 'releaseStatus',clcd:'release_status_cd' },
          { title: 'EW审核信息', key: 'ewAuditInfo' },
          { title: 'EW审核时间', key: 'ewTime' },
          { title: 'EW审核用户', key: 'ewUser' },
          { title: 'MW审核信息', key: 'mwAuditInfo' },
          { title: 'MW审核时间', key: 'mwTime' },
          { title: 'MW审核用户', key: 'mwUser' },
        ],
      }
    },
    computed: {

    },
    mounted() {
      this.getModule()
    },
    methods: {
      getModule(){
        const param = {pageNum:1,pageSize:9999}
        param.isDelete = '0'
        this.get('/tmBasModule/queryTmBasModule', param).then(res => {
          this.moduleOptions = res.list
        })
      },
      handleRowClick(row) {
        if (row) {
          this.chooseTable1 = row
          this.queryList1()
        } else {
          //清空子表数据
          this.chooseTable1 = {}
          this.tableData1 = []
        }
      },
      chooseTable(row){
        if(row){
          this.chooseData = row
        }else{
          this.chooseData = {}
        }
      },
      queryList() {
        this.tableData1 = []
        this.chooseData = {}
        this.chooseTable1 = {}
        this.$refs.table.query('/trBasModuleFiledAudit/queryTrBasModuleFiledAudit', this.formModel, '', false)
      },
      queryList1() {
        if(Object.keys(this.chooseTable1).length==0){
          this.$warn('请先选中一条模块基础信息列表中的数据!')
          return false
        }
        const param = {}
        param.isDelete = '0'
        param.tmBasModuleId = this.chooseTable1.tmBasModuleId
        param.markCode = this.chooseTable1.markCode
        this.$refs.table1.query('/trBasModuleFiledAudit/queryTrBasModuleFiledAuditDetailInfo', param, '', false)
      },
      handleAdd() {
        this.operType = 'add'
        this.dialogVisible = true
      },
      handleEw() {
        if(Object.keys(this.chooseData).length==0){
          this.$warn('请先选中一条详细信息列表中的数据!')
          return false
        }
        if(!this.hasAuthority(this.chooseData.tmBasModuleId)){
          this.$warn('用户不具有操作该模块的业务权限,请配置业务权限!')
          return false
        }
        if(this.chooseData.releaseStatus=='3'){
          this.$warn('该数据为历史版本,不能进行审核!')
          return false
        }
        if(this.chooseData.releaseStatus=='2'){
          this.$warn('该数据已发布,不能重复审核!')
          return false
        }
        if(this.chooseData.ewAuditInfo){
          this.$warn('该数据EW已审核,不能重复审核!')
          return false
        }
        this.operType = 'ewAudit'
        this.editData = this.chooseData || {}
        this.showAudit = true
      },
      handleMw(row) {
        if(Object.keys(this.chooseData).length==0){
          this.$warn('请先选中一条详细信息列表中的数据!')
          return false
        }
        if(!this.hasAuthority(this.chooseData.tmBasModuleId)){
          this.$warn('用户不具有操作该模块的业务权限,请配置业务权限!')
          return false
        }
        if(this.chooseData.releaseStatus=='3'){
          this.$warn('该数据为历史版本,不能进行审核!')
          return false
        }
        if(this.chooseData.releaseStatus=='2'){
          this.$warn('该数据已发布,不能重复审核!')
          return false
        }
        if(!this.chooseData.ewAuditInfo){
          this.$warn('该数据还未进行EW已审核,不能进行MW审核!')
          return false
        }
        if(this.chooseData.mwAuditInfo){
          this.$warn('该数据MW已审核,不能重复审核!')
          return false
        }
        this.operType = 'mwAudit'
        this.editData = this.chooseData || {}
        this.showAudit = true
      },
      handleAddVersion(row) {
        if(Object.keys(this.chooseData).length==0){
          this.$warn('请先选中一条详细信息列表中的数据!')
          return false
        }
        if(!this.hasAuthority(this.chooseData.tmBasModuleId)){
          this.$warn('用户不具有操作该模块的业务权限,请配置业务权限!')
          return false
        }
        this.operType = 'add'
        this.editData = this.chooseData || {}
        this.showAudit = true
      },
    }
  }
</script>

<style lang="scss" scoped>

</style>
